package com.zb.template.method;

import java.util.List;

import org.springframework.stereotype.Component;

import com.zb.util.CommonUtils;

import freemarker.ext.beans.DateModel;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

@Component("dateUtilMethod")
public class DateMethod implements TemplateMethodModelEx {

    @SuppressWarnings("rawtypes")
    public Object exec(List arguments) throws TemplateModelException {
        if (arguments != null && !arguments.isEmpty() && arguments.get(0) != null) {
            DateModel code = (DateModel) arguments.get(0);
            return new SimpleScalar(CommonUtils.DateToString(code.getAsDate()));
        }
        return null;
    }

}